import { defineConfig, loadEnv } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'

export default defineConfig(({ command, mode }) => {
  // 根据当前工作目录中的 `mode` 加载 .env 文件
  // 设置第三个参数为 '' 来加载所有环境变量，而不管是否有 `VITE_` 前缀。
  console.info(command) // default `serve`
  console.info(mode) // default `development`
  const env = loadEnv(mode, process.cwd(), '') as ImportMetaEnv
  const { VITE_APP_NAME, VITE_PORT } = env
  console.info(VITE_APP_NAME, VITE_PORT)
  return {
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
        '@assets': resolve(__dirname, 'src/assets'),
        '@components': resolve(__dirname, 'src/components'),
        '@views': resolve(__dirname, 'src/views')
      }
    },
    plugins: [
      vue()
    ],
    server: {
      port: VITE_PORT,
      open: true,
      host: '0.0.0.0'
    }
  }
})